﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using TheVerge.Base;
using TheVerge.Base.Platform;
using TheVerge.Base.Models;
using TheVerge.Phone.Controls;
using Microsoft.Phone.Shell;

namespace TheVerge.Phone.Pages
{
    public partial class ForumsPage : MainPage
    {
        private VMForums VM;

        public ForumsPage()
        {
            InitializeComponent();
            DataContext = VM = App.MainVM.Forums;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            App.MainVM.ActivePinnable = App.MainVM.Forums;
        }

        private void Forum_Click(object sender, RoutedEventArgs e)
        {
            var fe = sender as FrameworkElement;
            var forum = fe.DataContext as VMForum;

            VM.SetActiveForum(forum);

            NavigationService.Navigate(new Uri(@"/Pages/ForumEntriesPage.xaml", UriKind.Relative));
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            VM.Load();
        }
        
        protected override MainPage.PageSection Section
        {
            get { return MainPage.PageSection.Forums; }
        }
    }
}